layui.use(['table', 'form', 'jquery', 'common'], function() {
			let table = layui.table;
			let form = layui.form;
			let $ = layui.jquery;
			let common = layui.common;

			let cols = [
				[{
						title: 'ID',
						field: 'id',
						align: 'center',
						width: 100
					},
					{
						title: '用户名[管理员]',
						field: 'name',
						templet: "#name",
						align: 'center'
					},
					{
						title: '操作类型',
						field: 'logtxt',
						align: 'center',
					},
					{
						title: '操作IP',
						field: 'ip',
						align: 'center',
						templet:function(d){
						    return `<a href="javascript:chackip('${d.ip}')">${d.ip}</a>`;
						}
					},
					{
						title: '时间',
						field: 'time',
						align: 'center'
					},
					{
						title: '操作',
						toolbar: '#user-bar',
						align: 'center',
						width: 130
					}
				]
			]

			table.render({
				elem: '#user-table',
				url: '/h/ajax/LoggetDataList',
				page: true,
				cols: cols,
				cellMinWidth: 150,
				skin: 'line',
				toolbar: '#user-toolbar',
				defaultToolbar: [{
					title: '刷新',
					layEvent: 'refresh',
					icon: 'layui-icon-refresh',
				}, 'filter', 'print', 'exports']
			});

			table.on('tool(user-table)', function(obj) {
				if (obj.event === 'deleteLog') {
					window.deleteLog(obj);
				} else if (obj.event === 'allRemove') {
					window.allRemove(obj);
				}
			});

			table.on('toolbar(user-table)', function(obj) {
				if (obj.event === 'refresh') {
					window.refresh();
				} else if (obj.event === 'allRemove') {
					window.allRemove(obj);
				}
			});

			form.on('submit(user-query)', function(data) {
				// console.log(data.field)
				table.reload('user-table', {
					where: data.field,
					page:{curr: 1}
				})
				return false;
			});
            window.chackip = function(ip){
            	$.ajax({
					type: 'POST',
					url: "/h/ajax/chackip",
					data: {
					   ip:ip
					},
					dataType: 'json',
					success: function(data) {
						
						if (data.code == 200) {
						    // 使用layui表格样式
                            const tableContent = `
                                <table class="layui-table" lay-skin="link" lay-size="sm">
                                    <colgroup>
                                        <col width="120">
                                        <col>
                                    </colgroup>
                                    <tbody>
                                        <tr>
                                            <td>该IP所在省为</td>
                                            <td>${data.pro || '无'}</td>
                                        </tr>
                                        <tr>
                                            <td>该IP所在城市</td>
                                            <td>${data.city || '无' }</td>
                                        </tr>
                                        <tr>
                                            <td>IP地址</td>
                                            <td>${data.ip || '无' }</td>
                                        </tr>
                                        <tr>
                                            <td>详情</td>
                                            <td>${data.details || '无'}</td>
                                        </tr>
                                        <tr>
                                            <td>IP段</td>
                                            <td>${data.segment || '无'}</td>
                                        </tr>
                                    </tbody>
                                </table>`;
                                 // 使用layer弹窗展示
                                layer.open({
                                    type: 1,
                                    title: `ip详情`,
                                    area: ['450px', 'auto'],
                                    content: `<div style="padding: 15px;">${tableContent}</div>`,
                                    shadeClose: true,
                                });
						} else {
							layer.msg(data.msg, {
                                icon: 2,
                                time: 1000
                            });
						}
					},
					error: function(data) {
						layer.msg("服务器错误！", {
                            icon: 2,
                            time: 1000
                        });
						return false;
					}
            	});
            }

			window.deleteLog = function(obj) {
				// console.log(obj)
				layer.confirm('确定要删除该日志', {
					icon: 3,
					title: '提示'
				}, function(index) {
					layer.close(index);
					let loading = layer.load();
					$.ajax({
						type: 'POST',
						url: "/h/ajax/Del_log",
						data: {
							id: obj.data['id']
						},
						dataType: 'json',
						success: function(data) {
							layer.close(loading);
							if (data.code == 200) {
								layer.msg(data.msg, {
									icon: 1,
									time: 1000
								},function(){
								    table.reload('user-table');
								});
							} else {
								layer.msg(data.msg,{
								    icon: 2,
									time: 1000
								});
							}
						},
						error: function(data) {
						    layer.close(loading);
							layer.msg('服务器错误',{
								    icon: 2,
									time: 1000
								});
							return false;
						}
					});
				});
			}


			window.allRemove = function(obj) {
				layer.confirm('确定要清理这些日志', {
					icon: 3,
					title: '提示'
				}, function(index) {
					layer.close(index);
					let loading = layer.load();
					$.ajax({
						type: 'POST',
						url: "/h/ajax/Del_qblog",
						dataType: 'json',
						
						success: function(data) {
							layer.close(loading);
							if (data.code == 200) {
								layer.msg(data.msg, {
									icon: 1,
									time: 1000
								},function(){
								    table.reload('user-table');
								});
								
							} else {
								layer.msg(data.msg,{
								    icon: 2,
									time: 1000
								});
							}
						},
						error: function(data) {
						    layer.close(loading);
							layer.msg('服务器错误',{
								    icon: 2,
									time: 1000
								});
							return false;
						}
					});
				})
			}

			window.refresh = function(param) {
				table.reload('user-table');
			}
		})